<?php
/**
 * 更新商品基础数据
 *
 */
$argv[1] = 'dev.fh.taoex.com';
$argv[2] = '2012-11-16 00:00:00';
$argv[3] = '2012-11-16 23:59:59';

$domain = $argv[1];
$sDate = time()-86400;//strtotime($argv[2]);
$eDate = time();//strtotime($argv[3]);


define('COMMAND_MODE', true);

set_time_limit(0);
define('LIB_DIR', dirname(__FILE__) . '/lib/');
require_once(LIB_DIR . 'api/taobao/order.php');
require_once(dirname(__FILE__) . '/lib/init.php');

updateGoods();

function updateGoods() {

	
	
	
 
	
			$db = kernel::database();
			$row = 0;
			$n=0;
			$e=0;
			$handle = fopen("data/2013-1-14-1.csv","r");
			while ($data = fgetcsv($handle, 1000, "	")) {
				$num = count($data);
				//echo "			$num fields in line $row:			\n";
				$row++;
				// 				for ($c=0; $c < $num; $c++) {
				// 					echo $data[$c] . "
				// 					\n";
				// 				}
			
			
				$bn=$data[0];
				$store=$data[1];
					
			
			
				$sql = "select count(*) as _count from `sdb_ome_products` where barcode='$bn'";
				$r = $db->select($sql);
				$a = intval($r[0]['_count']);
				//echo $a.$sql;
				//continue;
				if($a >0){
					
					echo "已更新,".$store.','.$bn."\n";
					$n++;
			
					//更新货品库存
					$sql2 = "update `sdb_ome_products` set  store='$store'   where  barcode='$bn'";
					$sql3 = "update `sdb_ome_branch_product` set  store=$store  where  product_id=(select  product_id from sdb_ome_products where  barcode='$bn' LIMIT  1)";
			
					if($db->exec($sql2)){
						$db->exec($sql3);
					}else{
						echo "错误,".$store.','.$bn."\n";
						$e++;
					}
				}else{
			
					echo "未更新,".$store.','.$bn."\n";
			
				}
			
			
			}
			fclose($handle);
				
				
			
			
			
			echo "更新".$n."共".$row."错误".$e;
	 
			
}